{include file="common/head"/}

<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>修改</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">
        
        
    <div class="layui-form-item">
        <label class="layui-form-label"> 用户名 </label>
        <div class="layui-input-4">
            <input type="text" name="userName" ng-model="field.userName" lay-verify="required"  class="layui-input">
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label"> 密码 </label>
        <div class="layui-input-4">
             <input type="password" name="password"   placeholder="{:lang('pleaseEnter')}登录密码" lay-verify="required"class="layui-input">
        </div>
    </div>

    <div class="layui-form-item fieldName">  
      <label class="layui-form-label">头像</label> 
      <input type="hidden" class="pic"  name="pic" >
      <div class="layui-input-block"> 
         <div class="layui-upload">
           <button type="button" class="layui-btn layui-btn-primary uploadImg" ><i class="icon icon-upload3"></i>点击上传</button> 
           <div class="layui-upload-list"> 
              <img class="layui-upload-img" id="pic" >
                <p class="demoText" ></p> 
            </div>
         </div> 
      </div>
  </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-4">
            <input type="radio" name="status" ng-model="field.status" ng-checked="field.status==1" ng-value="1" title="启用">
            <input type="radio" name="status" ng-model="field.status" ng-checked="field.status==2" ng-value="2" title="未启用">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"> 备注 </label>
        <div class="layui-input-4">
            <input type="text" name="remark" ng-model="field.remark" lay-verify="required"  class="layui-input">
        </div>
    </div>

        
        


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}

 
<script src="/static/common/js/angular.min.js"></script>
<script>
    
      
       
    var m = angular.module('hd',[]);
    m.controller('ctrl',function($scope) {
        $scope.field = {$info|raw};
        layui.use(['form','upload', 'layer','layedit'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload,layedit = layui.layedit;
             
               
             var info = {$info|raw}; form.val("form", info);  if(info){ $("#pic").attr("src",info.pic); } 
var info = {$info|raw}; form.val("form", info);  if(info){ $(".pic").attr("value",info.pic); } 

              
             

            form.on('submit(submit)', function (data) {

                // 提交到方法 默认为本身
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                data.field.user_id = $scope.field.user_id;
                 //获取编辑器的内容
                $.post("", data.field, function (res) {
                    console.log(res);
                    layer.close(loading);
                    if (res.code > 0) {
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })


               
    var uploadInst = upload.render({ 
            elem: ".uploadImg" ,
            url: "{:url("UpFiles/upload")}" ,
            before: function(obj){
              var _this = this;
              obj.preview(function(index, file, result){
                   _this.item.parents(".fieldName").find("img").attr("src",result)
              });  
            },
            done: function(res){ 
                if(res.code>0){ 
                  this.item.parents(".fieldName").find("input[type=hidden]").val(res.url)
                }else{ 
                  return layer.msg("上传失败");
                } 
            } ,
              error: function(res){ 
                var demoText = this.item.parents(".fieldName").find(".demoText");
                 demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');  
                 demoText.find(".demo-reload").on("click", function(){  
                  uploadInst.upload(); 
                });
              }
        });


                
        });
    });


    // 时间插件shi-jian-cha-jian
    
    function useLayDateMultiple(cls) {
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            lay('#' + cls).each(function() {
                laydate.render({
                    elem : this,
                    trigger : 'click'
                });
            });
        });
    }
</script>
</body>
</html>